/*package ase.rcontrol;

import java.io.FileWriter;
import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import ase.interfaces.InterruptibleModule;
import ase.modules.Timer;

public class IRsender extends Thread implements InterruptibleModule{

	public static final int TIMER_ID = 0;
	
	 Interrupts 
	private LinkedBlockingQueue<Integer> interrupts = new LinkedBlockingQueue<Integer>();
	private ArrayBlockingQueue<Boolean> timerFlag = new ArrayBlockingQueue<Boolean>(1);
	private InterruptHandler intHandler = new InterruptHandler();
	
	private Timer timer = new Timer(25,0, this, TIMER_ID);
	
	private IRLed led = new IRLed();
	
	private BlockingQueue<String> buf = new LinkedBlockingQueue<String>();;
	
	private String address;
	
	public IRsender(String address){
		this.address = address;
	}
	
	public void sendCommand(String cmd){
		
		if(cmd.length() != 6) return;
		
		try {

			buf.put(cmd);

		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private void waitForTimer(){
		try {
			timerFlag.take();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private void sendBit1(){
		waitForTimer();
		led.turnOn();
		waitForTimer();
		led.turnOff();
	}
	
	private void sendBit0(){
		waitForTimer();
		led.turnOff();
		waitForTimer();
		led.turnOn();
	}
	
	private void sendStartBits(){
		
		// Two "1" bits
		sendBit1();
		sendBit1();
	}
	
	private void sendAddressBits(){
		
		for(int i = 0; i < 5; i++)
			if(address.charAt(i) == '0') sendBit0();
			else sendBit1();
	}
	
	private void sendCommandBits(String cmd){
		
		for(int i = 0; i < 6; i++)
			if(cmd.charAt(i) == '0') sendBit0();
			else sendBit1();
	}
	
	public void run(){
		
		String cmd;
		led.turnOff();
		timer.start();
		intHandler.start();
		while(true){
			try {
				cmd = buf.take();
				timerFlag.poll(); // Clean timerFlag
				sendStartBits();
				sendBit0(); // Toogle bit (ignored)
				sendAddressBits();
				sendCommandBits(cmd);
				// End of the command
				waitForTimer();
				led.turnOff();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	
	class IRLed{
		
		public void turnOn(){
			try {
				FileWriter out = new FileWriter("IR");
				out.write('1');
				out.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		public void turnOff(){
			try {
				FileWriter out = new FileWriter("IR");
				out.write('0');
				out.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	@Override
	public void interruptModule(int id) {
		
		this.interrupts.offer(id);
	}
	
	private class InterruptHandler extends Thread{
		
		public InterruptHandler(){
			setDaemon(true);
		}
		
		public void run(){
			
			int id;
			
			while(true){
				
				try {
					id = interrupts.take();
				} catch (InterruptedException e) {
					return;
				}
				
				// TODO suspend thread
				timerFlag.offer(true);
				// TODO resume thread
			}
			
		}
	}
}*/
